<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="/resource/UserPwoer.tld" prefix="p"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	pageContext.setAttribute("fnId", request.getAttribute("fnId"));
	pageContext.setAttribute("userPwoer", request.getSession().getAttribute("userPwoer"));
%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<LINK rel="Bookmark" href="../images/favicon.ico">
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
	<style type="text/css">
	.none{
	display:none;
	}
	.dropdown-menu{min-width:0;width:65px;}
		.input-list label{
		width:28%;
	}
	.ml-20{
		margin-left:1%;		
	}
	.mt-20{
		margin-bottom:10px;
	}
	.input-list .form-control{
    display: inline-block;
    width: 100%;
    vertical-align: middle;
    }
    .input-list .form-group {
    display: inline-block;
    margin-bottom: 0;
    vertical-align: middle;
    width:68%;
	}
	#mgrid>tr>td{
	padding-top: 10px !importer;
	
}
	</style>
	
	
</head>
<body class="gray-bg">
	<nav class="huiNav">
	<%@include file="project-nav.jsp" %>bug管理
		<a class="btn btn-info  btn-sm pull-right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="fa fa-refresh"></i></a>
	</nav>

	<div class="ibox-content">
	<!-- 搜索框部分start -->
	<%-- <p:btn value="serch"> --%>
		<form class="form-inline" id="serchform">
		   	<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
		    <input type="hidden" name="projId" id="projId" value="${param.projId}"> 
				<label for="exampleInputName2">标&nbsp;题</label>
				<input name="title" type="text" class="form-control">
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">编&nbsp;号</label>
				<input name="bugNo" type="text" class="form-control">
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">状&nbsp;态</label>
				<select class="form-control autoFull" name="status"
					data-url="${path}/admin/dataDictionary/showDataDictionary" 
					data-filed="name" 
					data-value="name"
					data-param="{type:'bug状态'}"
					>
					<option value="">--请选择状态--</option>
				</select>
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">类&nbsp;型</label>
				<select class="form-control autoFull" name="kind"
					data-url="${path}/admin/dataDictionary/showDataDictionary" 
					data-filed="name" 
					data-value="name"
					data-param="{type:'bug类型'}"
					>
					<option value="">--请选择bug类型--</option>
				</select>
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
			    <label class="exampleInputName2">方&nbsp;案</label>
				<select class="form-control autoFull" name="type" 
					data-url="${path}/admin/dataDictionary/showDataDictionary" 
					data-filed="name" 
					data-value="name"
					data-param="{type:'解决方案'}"
					>
					<option value="">--请选择方案--</option>
				</select>
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">创建人</label>
				<select class="form-control autoFull" name="createUserId" 
					data-url="${path}/admin/projUser/showListByModel" 
					data-filed="userName" 
					data-value="userId"
					data-param="{projId:'${param.projId}'}"
					>
					<option value="">--请选择创建人--</option>
				</select>
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">指派人</label>
				<select class="form-control autoFull" name="userId" id="userId"
					data-url="${path}/admin/projUser/showListByModel" 
					data-filed="userName" 
					data-value="userId"
					data-param="{projId:'${param.projId}'}"
					>
					<option value="">--请选择指派给谁--</option>
				</select>
			</div>
			<div class="col-sm-4 col-md-3 col-xs-6 mt-20 ">		
				<label for="exampleInputName2">责任人</label>
				<select class="form-control autoFull" name="ownerUserId"  id="ownerUserId"
					data-url="${path}/admin/projUser/showListByModel" 
					data-filed="userName" 
					data-value="userId"
					data-param="{projId:'${param.projId}'}"
					>
					<option value="">--请选择责任人--</option>
				</select>
			</div>
			<button  onclick="myGrid.serchData()" type="button" class="btn btn-info btn-sm"><i class="fa fa-search " ></i> 搜索</button>
			<button  type="reset" class="btn btn-info btn-sm"><i class="fa fa-refresh " ></i> 重置</button>
		</form>
	<%-- 	</p:btn> --%>
	<!-- 搜索框部分en -->
		<div class="option-bar" >
		<%-- <p:btn value="dels">
			<button onclick="myGrid.delItems()" type="button" class="btn btn-danger btn-sm"><i class="fa fa-trash" ></i>批量删除</button>
		</p:btn>
		--%>
			<button onclick="openAdd()" type="button" class="btn btn-success btn-sm"><i class="fa fa-plus" ></i>  新增</button>
		</div>
		<table id="mgrid" class="table table-no-bordered table-striped" >
			<thead>
				<tr>
					<th data-checkbox="true"  ></th>
					<th data-field="grade" data-sortable="true" data-formatter="buidTitle" >BUG</th>
					<th data-field="lastNoticeTime" data-sortable="true" data-formatter="getDays">响应时间</th>
					<th data-field="ownerUserName" >责任人</th>
					<th data-field="handleUserName" >解决者</th>
					<th data-field="handleTime" data-width="100px" data-formatter="MGrid.getTimeDD" >解决时间</th>
					<th data-field="type" >方案</th>
					<th data-align="center"  data-width="100px" data-field="id" data-formatter="buidOperate">操作</th>
				</tr>
			</thead>
		</table>
	</div>
	
	<script type="text/javascript">
	

	var myGrid;
	var projId;
		$(function(){
			 
			  
			//  projId=$.query.get('projId');
			 // $("#userId").attr('data-param','{projId:'+projId+'}')
			  MTools.autoFullSelect();
			 // $("#projId").val(projId);
			  myGrid=MGrid.initGrid({
				 url:"${path}/admin/bug/showList",
				 delUrl:"${path}/admin/bug/del",
				 clickToSelect:false,
				 sortName:"createTime",
				 sortOrder:"desc",
				 onClickCell:function(field, value, row, $element){
					 if(field!='id'){
					 layer.full(
						 layer.open({
								type:2,
								title:"bug查看",
								maxmin:true,
								cancel:function(){
									myGrid.serchData();
								},
								content:['${path}/admin/bug/showForm?id=' + row.id]
							}) 
					 );
					 }
				 }
			 }); 
		});
		/**
		构建标题
		**/
		function buidTitle(value, row, index){
			
			var level=row.grade;
			var color='';
				if(level == '1'){
					color = 'danger';
				}else if(level == '2'){
					color = 'warning';
				}else if(level == '3'){
					color = 'success';
				}else if(level == '4'){
					color = 'info';
				}
			var html='  <blockquote class=" text-'+color+'" ><small>' +MTools.farmterTime(row.createTime)+',['+row.createUserName+']创建'+ row.grade +'级BUG '+'指派给['+row.assignUserName+']</small><h3>（#'+row.bugNo+"） "+row.title+'</h3></blockquote>';
			html+="<span class='label label-"+color+" mr-5' >"+(row.kind==null?'默认':row.kind)+"</span>";
			html+="<span class='label label-"+color+" mr-5' >"+row.status+"</span>";
			html+="<span class='label  mr-5' >"+row.interfaceName+"</span>";
			
			
			return html;
		}
		
		
		function buidOperate(value, row, index){
			var html="";
			var onfirm="",assign="",handle="",close="",active="";
			console.log(row.status);
		    switch(row.status){
		    case "确认":
		    	confirm="none";
		    	active="none";
		    	break;
		    case "指派":
		    	active="none";
		    	break;
		    case "解决":
		    	confirm="none";
		    	handle="none";
		    	break;
		    case "关闭":
		    	confirm="none";
		    	handle="none";
		    	close="none";
		    	break;
		    case "激活":
		    	active="none";
		    	break;
		    }
		    console.log("onfirm:"+onfirm+"assign:"+assign+"handle:"+handle+"close:"+close+"active:"+active);
/* 			html+='<button class="btn btn-default btn-sm mr-5 '+confirm+'" onClick="openConfirm('+value+')"  title="确认"><i class="fa fa-search"></i></buttoun>'
 */			/* html+='<button class="btn btn-default btn-sm mr-5 '+assign+'" onClick="openAssign('+value+')"  title="指派"><i class="fa fa-hand-o-right"></i></buttoun>'
			html+='<button class="btn btn-default btn-sm mr-5 '+handle+'" onClick="openHandle('+value+')"  title="解决"><i class="fa fa-check-square"></i></buttoun>'
			html+='<button class="btn btn-default btn-sm mr-5 '+close+'" onClick="openClose('+value+')"  title="关闭"><i class="fa fa-close"></i></buttoun>'
			html+='<button class="btn btn-default btn-sm mr-5" onClick="openEdit('+value+')"  title="编辑"><i class="fa fa-edit"></i></buttoun>'
			html+='<button class="btn btn-default btn-sm mr-5 '+active+'" onClick="openActive('+value+')"  title="激活"><i class="fa fa-reply"></i></buttoun>'
			 */
			html+='<div class="btn-group">'+
					  '<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">'+
			    		'操作 <span class="caret"></span>'+
					  '</button>'+
					  '<ul class="dropdown-menu" role="menu">'+
					    '<li style="float:left"><a href="javascript:void(0)" style="display:'+assign+'"  onClick="openAssign('+value+')" title="指派"><i class="fa fa-hand-o-right"></i></a></li>'+
					    '<li style="float:left"><a href="javascript:void(0)" style="display:'+handle+'"  onClick="openHandle('+value+')" title="解决"><i class="fa fa-check-square"></i></a></li>'+
					    '<li style="float:left"><a href="javascript:void(0)" style="display:'+close+'"  onClick="openClose('+value+')" title="关闭"><i class="fa fa-close"></i></a></li>'+
					    '<li style="float:left"><a href="javascript:void(0)" onClick="openEdit('+value+')"  title="编辑"><i class="fa fa-edit"></i></a></li>'+
					    '<li style="float:left"><a href="javascript:void(0)" style="display:'+active+'" onClick="openActive('+value+')" title="激活"><i class="fa fa-reply"></i></a></li>'+
					  '</ul>'+
					'</div>'
				html+='';
			return html; 
		}
		//打开添加界面
		function openAdd() {
			layer.full(
			layer.open({
				type : 2,
				title : "添加bug",
				area : [ MUI.SIZE_L, '500px' ],
				content : [ '${path}/admin/bug/editForm?projId=${param.projId}']
			}));
		}
		//打开编辑界面
		function openEdit(id,type) {
			layer.full(
			layer.open({
				type : 2,
				title : "编辑bug",
				area : [ MUI.SIZE_L, '500px' ],
				maxmin : true,
				content : [ '${path}/admin/bug/editForm?id=' + id+'&projId=${param.projId}']
			}));
		}
		
		
		
		//打开解决界面
		function openHandle(id) {
			layer.open({
				type : 2,
				title : "解决bug",
				area : [ MUI.SIZE_L, '500px' ],
				maxmin : true,
				content : [ '${path}/admin/bug/toHandleBug?bugId=' + id+'&&type=解决']
			});
		}
		
		//打开指派页面
		function openAssign(id){
			layer.open({
				type:2,
				title:"指派",
				area:[ MUI.SIZE_L, '500px'],
				maxmin:true,
				content:['${path}/admin/bug/toHandleBug?bugId=' + id+'&&type=指派']
			});
		}
		
		//打开指派页面
		function openClose(id){
			layer.open({
				type:2,
				title:"关闭",
				area:[ MUI.SIZE_L, '500px'],
				maxmin:true,
				content:['${path}/admin/bug/toHandleBug?bugId=' + id+'&&type=关闭']
			});
		}
		//激活
		function openActive(id){
			layer.open({
				type:2,
				title:"激活",
				area:[ MUI.SIZE_L, '500px'],
				maxmin:true,
				content:['${path}/admin/bug/toHandleBug?bugId=' + id+'&&type=激活']
			});
		}
		
		//改变bug等级样式		
		function changeLevelStyle(value, row, index){
			var html="";
			if(value == '1'){
				html = '<span class="badge badge-danger">一级bug</span>';
			}else if(value == '2'){
				html = '<span class="badge badge-warning">二级bug</span>';
			}else if(value == '3'){
				html = '<span class="badge badge-success">三级bug</span>';
			}else if(value == '4'){
				html = '<span class="badge badge-info">四级bug</span>';
			}
			return html;
		}
		
		//计算响应时间与现在距离的天数
		function getDays(value,row,index){
			var gapDays="";
			console.log(value);
			if(value!=null && value!=''){
			//var responseDate=new Date(value)
			//var responseDateStr=responseDate.getFullYear()+"-"+(responseDate.getMonth()+1)+"-"+responseDate.getDate();
			//var responseTime=new Date(responseDateStr).getTime();
			var nowDate=new Date()
			//var nowDateStr=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
			//var nowTime=new Date(nowDateStr).getTime();
			var days=parseInt((nowDate.getTime()-value)/(1000*60*60*24));
				if(days<=0){
					return "今天";
				}else{
					gapDays=days+"天前";
				}
			}
			
			return gapDays;
		}
		
	</script>
</body>
</html>
